<template>
  <div>
    <p>ref可以直接读取到值，而不用.value，a = {{ a }}</p>

    <p>toRef用法：toRef(object, key)，将对象的某个属性变成响应式</p>

    <p>toRefs用法：toRefs(object | Array)</p>
  </div>
</template>

<script>
import { ref, toRef, toRefs, watch } from 'vue'

export default {
  setup() {
    // ref
    const a = ref(0)
    const d = ref(1)
    // toRef
    const b = { value: 1 }
    // toRefs
    const c = { value: 1 }

    const clean = watch([a, d], (newV, oldV, cb) => {
      console.log(newV)
      clean()
    })

    watch(a, (newV) => {
      console.log(`2-${newV}`)
    })

    setTimeout(() => {
      a.value = 2
      d.value = 3
      setTimeout(() => {
        a.value = 4
      }, 3000)
    }, 1000)

    return {
      a
    }
  }
}
</script>

<style>

</style>